from month02.day03.squeue import LQueue


# 二叉树的节点类
class TreeNode:
    def __init__(self, data=None, left=None, right=None):
        self.data = data
        self.left = left
        self.right = right


# 二叉树类
class Bitree:
    def __init__(self, root=None):
        self.root = root

    # 判断是否为空
    def is_empty(self):
        if self.root is None:
            return True
        else:
            return False

    # 前序遍历
    def preOrder(self, node):
        if node is None:
            return
        print(node.data)
        self.preOrder(node.left)
        self.preOrder(node.right)

    # 中序遍历
    def inOrder(self, node):
        if node is None:
            return
        self.preOrder(node.left)
        print(node.data)
        self.preOrder(node.right)

    # 后续遍历
    def postOrder(self, node):
        if node is None:
            return
        self.preOrder(node.left)
        self.preOrder(node.right)
        print(node.data)

    # 层次遍历
    def levelOrder(self, node):
        qu = LQueue()
        qu.enqueue(node)  # 先将结点入队
        while not qu.is_empty():
            node = qu.dequeue()
            print(node.data, end="")
            if node.left:
                qu.enqueue(node.left)
            if node.right:
                qu.enqueue(node.right)
